package edu.dayu.aop;

import edu.dayu.util.CurrentLimitUtil;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class CurrentAspect {
    @Autowired
    private CurrentLimitUtil currentLimitUtil;

    @Pointcut("@annotation(current)")
    public void pointcut(Current current){

    }

    @Before("pointcut(current)")
    public void before(Current current){
        boolean flag = currentLimitUtil.current(current.name(),current.count(),current.time());
        if (!flag){
            System.out.println(current.name()+"接口已限流");
        }
    }
}
